package com.learn.jdk21.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;

@Service
@Slf4j
@EnableAsync
public class AsyncService {

    /**
     * @param countDownLatch 用于测试
     */
    @Async
    public void doSomething(CountDownLatch countDownLatch) throws InterruptedException {
        Thread.sleep(50);
        log.info("Thead {} is virtual : {}", Thread.currentThread(), Thread.currentThread().isVirtual());
        countDownLatch.countDown();
    }
}
